/**
 * @file    sysfile.c
 *
 * @author  Li.Hua <lihua_338@163.com>.
 *
 * @date    2017-01-16
 *
 * @brief
 *
 * @note
 *
 * Modification history
 * ----------------------------------------------------------------------------
 * Date         Version  Author       History
 * ----------------------------------------------------------------------------
 *
 */
#include <stdio.h>
#include <stdint.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <stdint.h>
#include "sysfile.h"

#define scp_info printf

int sys_open(const char *filename, uint32_t flags, uint32_t mode)
{
    int retval = 0;

    scp_info("%s(\"%s\", %x, %x)......", __FUNCTION__, filename, flags, mode);    
    retval = open(filename, flags, mode);

    scp_info("%s(\"%s\", %x, %x)=%d", __FUNCTION__, filename, flags, mode, retval);

    return retval;
}

ssize_t sys_read(int fd, void *buf, size_t count)
{
    int retval = 0;

    retval = read(fd, buf, count);

    scp_info("%s(%d, %p, %d)=%d", __FUNCTION__, fd, buf, (uint32_t)count, retval);

    return retval;
}

ssize_t sys_write(int fd, const void *buf, size_t count)
{
    int retval = 0;

    retval = write(fd, buf, count);

    scp_info("%s(%d, %p, %d)=%d", __FUNCTION__, fd, buf, (uint32_t)count, retval);

    return retval;
}

loff_t sys_lseek(int fd, loff_t offset, int origin)
{
    loff_t retval = 0;

    retval = lseek(fd, offset, origin);

    scp_info("%s(%d, %d, %d)=%d", __FUNCTION__, fd, (int)offset, origin, (int)retval);
    return retval;
}

int sys_ioctl(int fd, unsigned int cmd, unsigned long arg)
{
    int retval = 0;

    retval = ioctl(fd, cmd, arg);

    scp_info("%s(%d, %08x, %08lx)=%d", __FUNCTION__, fd, cmd, arg, retval);
    return retval;
}

int sys_ioctl2(int fd, unsigned int cmd, unsigned long arg, unsigned long arg1)
{
    int retval = 0;

    retval = ioctl(fd, cmd, arg, arg1);

    scp_info("%s(%d, %08x, %08lx, %08lx)=%d", __FUNCTION__, fd, cmd, arg, arg1, retval);
    return retval;
}

int sys_close(int fd)
{
    int retval = 0;

    retval = close(fd);

    scp_info("%s(%d)=%d", __FUNCTION__, fd, retval);
    return retval;
}

int sys_unlink(const char *filename)
{
    int retval = 0;

    retval = unlink(filename);

    scp_info("%s(\"%s\")=%d", __FUNCTION__, filename, retval);
    return retval;
}

int sys_ftruncate(int fd, off_t length)
{
    int retval = 0;

    retval = ftruncate(fd, length);

    scp_info("%s(%d, %d)=%d", __FUNCTION__, fd, (int)length, retval);
    return retval;
}


